﻿using System;
using System.Collections.Generic;
using System.Text;

namespace OOP
{
    class InterfaceDemo2
    {
        //static void Main(string[] args)
        //{
        //    IPhone nokia = new Nokia();
        //    PhoneUser phoneUser = new PhoneUser(nokia);
        //    phoneUser.UsePhone();
        //}
    }

    class PhoneUser
    {
        //使用接口解耦合，降低用户 类对手机类的依赖。
        private IPhone phone;
        public PhoneUser(IPhone phone)
        {
            this.phone = phone;
        }       
        public void UsePhone()
        {
            phone.Ring();
            phone.PickUp();
            phone.Receive();
            phone.Send();
        }
    }
    interface IPhone
    {
        void Ring();
        void PickUp();
        void Send();
        void Receive();
    }
    class Nokia : IPhone
    {
        public void PickUp()
        {
            Console.WriteLine("Hello ,this is Tim");
        }

        public void Receive()
        {
            Console.WriteLine("I received message");
        }

        public void Ring()
        {
            Console.WriteLine("Nokia ring...");
        }

        public void Send()
        {
            Console.WriteLine("Send message");
        }
    }

    class XiaoMi : IPhone
    {
        public void PickUp()
        {
            Console.WriteLine("Hello ,this is Tim");
        }

        public void Receive()
        {
            Console.WriteLine("I received message");
        }

        public void Ring()
        {
            Console.WriteLine("XiaoMi ring...");
        }

        public void Send()
        {
            Console.WriteLine("Send message");
        }
    }
}
